<?php 
	function pagination($numRows,$from,$rows_per_page)
	{
		if ($numRows == 0) {
			echo '<span class="total">No posts</span>';
			return;
		}
		$numPages = ceil($numRows/$rows_per_page); //Number of pages
		$curPage = (int)($from/$rows_per_page) + 1; //Curent pages
		$p = 2; //Show 5 page
		$left = $curPage - $p;
		if ($left <= 0) {
			$left = 1;
			$right = 5;
		}
		else {
			$right = $curPage + 2;
		}
		if ($right > $numPages) {
			$right = $numPages;
			$left = $numPages - 4;
		}
		if ($left <= 0) {
			$left = 1;
		}

		echo '<span class="total">Page '.$curPage.' of '.$numPages.'</span>';
		echo '<ul class="pagination">';
		for ($i = $left; $i <= $right; $i++) {
			if ($i == $curPage) {
				echo '<li class="page-item"><span class="current">'.$i.'</span>';
			}
			else {
				echo '<li class="page-item"><a onclick="changePage(this);" href="#">'.$i.'</a>';
			}
			echo '</li>';
		}
		echo '</ul>';
	}
?>